package com.xucy.springboot.activemq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.ObjectMessage;
import java.util.List;

/**
 * @Author xucy
 * @Date 2019-07-05 14:35
 * @Description
 **/
@Component
public class MyTopicConsumer {

    Logger logger= LoggerFactory.getLogger(MyTopicConsumer.class);

    @JmsListener(destination="myTopic",containerFactory="jmsListenerContainerTopic")
    public void receiveTopicString(String msg){
        logger.info("接收的主题是："+msg);
    }

    @JmsListener(destination="myTopicList",containerFactory = "jmsListenerContainerTopic")
    public void receiveTopicListString(List<String> strings){
        for(String s:strings){
            logger.info(s);
        }
    }

    @JmsListener(destination="myTopicObject",containerFactory="jmsListenerContainerTopic")
    public void receiveObject(ObjectMessage objectMessage) throws Exception{
        User user=(User)objectMessage.getObject();
        logger.info(user.getName()+":"+user.getAge());
    }

    @JmsListener(destination="myTopicListObject",containerFactory="jmsListenerContainerTopic")
    public void receiveObjectList(ObjectMessage objectMessage) throws Exception{
        List<User> users=(List<User>)objectMessage.getObject();
        for(User user:users){
            logger.info(user.getName()+":"+user.getAge());
        }
    }
}
